<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="${package}.mapper.${className}Mapper">

	<!-- 可根据自己的需求，是否要使用 -->
	<resultMap type="${package}.entity.${className}" id="BaseResultMap">
	<#list allColumns as column>
		<result property="${column.attrname}" column="${column.columnName}"/>
	</#list>
	</resultMap>
    
	<sql id="Base_Column_List" >    
		<#list allColumns as column>${column.columnName}<#if column_has_next>,</#if></#list>
	</sql>

	<#if pk?size!=0 >  
	<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.String" >
		select 
		<include refid="Base_Column_List" />
		from ${tableName}
		where 
		<#list pk as p>${p.columnName}=${r"#{"}${p.attrname}${r"}"}<#if p_has_next> and </#if></#list>
	</select>
	</#if> 

	<select id="selectByFilter" resultMap="BaseResultMap">
		select
		<include refid="Base_Column_List" />
		from ${tableName} where 1=1 
		<#list allColumns as column>
		<if test="${objName}.${column.attrname} != null <#if column.attrType?? && column.attrType == "String" >and ${objName}.${column.attrname} != ''</#if>" >
			AND ${column.columnName}=${r"#{"}${objName}.${column.attrname}${r"}"}
		</if>
		</#list>
	</select>

	<delete id="deleteByPrimaryKey" parameterType="java.lang.String" >
		delete from ${tableName} where 1=1 and 
		<#list pk as p>${p.columnName}=${r"#{"}${p.attrname}${r"}"}<#if p_has_next> and </#if></#list>
	</delete>
	
	<insert id="insertSelective" parameterType="${package}.entity.${className}" >
		insert into ${tableName}
		<trim prefix="(" suffix=")" suffixOverrides="," >
			<#list allColumns as column>
			<if test="${column.attrname} != null">
				${column.columnName},
      		</if>
			</#list>
      	</trim>
		<trim prefix="values (" suffix=")" suffixOverrides="," >
			<#list allColumns as column>
			<if test="${column.attrname} != null" >
				${r"#{"}${column.attrname}${r"}"},
			</if>
			</#list>
		</trim>
	</insert>
	
	<update id="updateByPrimaryKeySelective" parameterType="${package}.entity.${className}" >
		update ${tableName}
		<set>
			<#list allColumns as column>
			<if test="${column.attrname} != null" >
				${column.columnName}=${r"#{"}${column.attrname}${r"}"},
			</if>
			</#list>
		</set>
		where <#list pk as p>${p.columnName}=${r"#{"}${p.attrname}${r"}"} <#if p_has_next>and</#if></#list>
	</update>
	
</mapper>